import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'


export default defineConfig({
    plugins: [
        vue(),
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        })],
    server: {
        port: 3000
    },
    compilerOptions: {isCustomElement: tag => tag === 'Sidebar'},
    build: {
        minify: 'terser', // 使用 terser 进行压缩
        terserOptions: {
            compress: {
                drop_console: true, // 删除 console.log
            },
        },
        rollupOptions: {
            output: {
                // 主入口JS文件
                entryFileNames: 'js/index.js',

                // 其他chunk文件
                chunkFileNames: 'js/chunks/[name].js',

                // 静态资源文件
                assetFileNames: (assetInfo) => {
                    if (assetInfo.name?.endsWith('.css')) {
                        return 'css/index.css'  // CSS文件直接命名
                    }
                    // 其他资源保持默认结构
                    return 'assets/[name].[ext]'
                }
            }
        }
    }
});
